import 'package:architecture/shared_preference.dart';
import 'package:get/get.dart';
import 'package:study_demo/constant/keys.dart';
// import 'package:win32_registry/win32_registry.dart';

import '../../base/BaseController.dart';
import '../../base/theme_controller.dart';

class SettingController extends ThemeController {
  final isChecked = false.obs;

  final themeModes = ['浅色', '深色'];

  @override
  onInit() {
    super.onInit();
    isChecked.value = readBool(IS_AUTO_START) ?? false;
  }

  changeStatus() {
    isChecked.value = !isChecked.value;
    saveBool(IS_AUTO_START, isChecked.value);
    _setAutostart(isOpen: isChecked.value);
  }

  final APP_KEY = 'cornucopia';
  final APP_PATH =
      r'D:\Work\Project\study_demo\build\windows\x64\runner\Release\study_demo.exe';

  void _setAutostart({bool isOpen = false}) async {
    try {
      // 创建或打开注册表键
      // const keyPath = r'Software\Microsoft\Windows\CurrentVersion\Run';
      // final key = Registry.openPath(RegistryHive.currentUser,
      //     path: keyPath, desiredAccessRights: AccessRights.allAccess);
      if (isOpen) {
        print('创建key');
        // key.createValue(RegistryValue(
        //     APP_KEY, // 键名值
        //     RegistryValueType.string,
        //     APP_PATH // 键// 值类型
        //     ));
      } else {
        // if (key.subkeyNames.contains(APP_KEY)) {
        // key.deleteKey(APP_KEY, recursive: true);
        // key.createValue(RegistryValue(
        //     APP_KEY, // 键名值
        //     RegistryValueType.string,
        //     '' // 键// 值类型
        //     ));
        // // }
      }
      // key.close();
      toast('设置成功');
    } catch (e) {
      print('e$e');
      toast('设置失败');
    }
  }
}
